package com.sundi.ecpay.task;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.sundi.ecpay.config.TradeStatus;
import com.sundi.ecpay.entity.EcOrder;
import com.sundi.ecpay.entity.Orders;
import com.sundi.ecpay.service.IEcOrderService;
import com.sundi.ecpay.service.IOrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class OrderTask {

    @Autowired
    IEcOrderService orderService;

    /**
     * 处理调单
     */
    @Scheduled(cron = "0/30 * * * * ?")
    @Async
    public void order(){
        log.info("每隔30秒去数据库查询未支付并且支付方式为支付宝扫码支付的订单,调用支付宝查询接口,处理业务逻辑");

        Wrapper<EcOrder> wrapper = new EntityWrapper<EcOrder>();
        wrapper.eq("aftersale_status",0);
        List<EcOrder> list = orderService.selectList(wrapper);
        for (EcOrder ecOrder : list){
            ecOrder.setAftersaleStatus(1);
            orderService.updateById(ecOrder);
        }
        log.info("处理掉单成功 结束！");
    }


}
